<?php 
 class ssh {
 var $stream;
 var $connection;
 var $data;
 function connect($host,$login,$pass,$port) {
 $this->connection = ssh2_connect($host, $port);
 return ssh2_auth_password($this->connection, $login, $pass);
 }
 function cmd ($cmd) {
 if( !($this->stream=ssh2_exec($this->connection,$cmd )) ) {
 echo "fail: unable to execute command<br>";
 }
 else {
 stream_set_blocking($this->stream, true );
 $this->data = "";
 while( $buf = fread($this->stream,4096) ) {
 $this->data .= $buf;
 }
 }
 return $this->data;
 }
 function close () {
 fclose($this->stream);
 }
 };
 $S = new ssh();
 $S->connect('10.11.20.200', 'ubnt', 'ubnt', '22');
 echo $S->cmd("reboot");
 $S->close();
?>